package com.iknow.task;

import android.location.Location;
import com.iknow.util.Loger;
import com.iknow.xmpp.service.aidl.IKnowUser;
import com.iknow.xmpp.service.aidl.IXmppConnection;
import com.iknow.xmpp.service.aidl.IXmppFacade;

public class LocationTask extends GenericTask
{
  public static final int ACTION_QUERY_BY_POS = 2;
  public static final int ACTION_REFRESH = 3;
  public static final int ACTION_UPLOAD_MY_LOC = 1;
  public static final String TAG = "LocationTask";
  private int mActionCode = 0;
  private String mErrorMessage;

  protected TaskResult _doInBackground(TaskParams[] paramArrayOfTaskParams)
  {
    TaskResult localTaskResult;
    TaskParams localTaskParams = paramArrayOfTaskParams[0];
    try
    {
      IXmppFacade localIXmppFacade = (IXmppFacade)localTaskParams.get("xmpp");
      if (!(localIXmppFacade.createConnection().isAuthentificated()))
      {
        this.mErrorMessage = "网络超时，请稍后再试";
        localTaskResult = TaskResult.FAILED;
      }
      else
      {
        Location localLocation = (Location)localTaskParams.get("loc");
        this.mActionCode = localTaskParams.getInt("action");
        if (this.mActionCode == 1)
        {
          localIXmppFacade.createConnection().getIKnowUser().updateUserLocation(localLocation.getLongitude(), localLocation.getLatitude());
          localTaskResult = TaskResult.OK;
        }
        else if (this.mActionCode == 2)
        {
          int i = localTaskParams.getInt("limit");
          localIXmppFacade.createConnection().getIKnowUser().getNearByFriends(localLocation.getLongitude(), localLocation.getLatitude(), i, 0, 20);
          localTaskResult = TaskResult.OK;
        }
      }
    }
    catch (Exception localException)
    {
      this.mErrorMessage = "网络超时，请稍后再试";
      Loger.e("LocationTask", localException.getMessage());
      localException.printStackTrace();
      localTaskResult = TaskResult.FAILED;
    }
    return localTaskResult;
  }

  public int getActionCode()
  {
    return this.mActionCode;
  }

  public String getErrorMessage()
  {
    return this.mErrorMessage;
  }
}